package com.example.mitsuki_momo_livestreamingschedule;

import com.alibaba.fastjson.JSON;
import com.example.mitsuki_momo_livestreamingschedule.model.PublicEvents;
import com.example.mitsuki_momo_livestreamingschedule.util.TimeUtil;
import com.example.mitsuki_momo_livestreamingschedule.util.TxtBuildUtil;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@SpringBootApplication
public class MitsukiMomoLiveStreamingScheduleApplication {

    @Resource
    public static RestTemplate restTemplate = new RestTemplate();

    public static void main(String[] args) {

        HttpHeaders headers = new HttpHeaders();
//        headers.set("Cookie", "_session_id=634ea99f3aebc910cff1479e75e12a78");
        headers.set("x-timetreea", "web/2.1.0/zh-CN");
        HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity(null, headers);

        PublicEvents body = restTemplate.exchange("https://timetreeapp.com/api/v1/public_calendars/115805/public_events?limit=30&string_id=true&utc_offset=28800&since="+TimeUtil.getDailyStartTime()+"&until="+TimeUtil.getMonthEndTime()+"", HttpMethod.GET, request, PublicEvents.class).getBody();
        System.out.println(JSON.toJSONString(body));
        TxtBuildUtil.buildIcs(body);
    }



}
